/**
 * 单独执行的爬取详情的命令
 */
const fetchByUrl = require('./fetch');
function printLine() {
  console.log('-------------------');
}
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
console.clear();
if (process.argv[2]) {
  (async () => {
    const res = await fetchByUrl(process.argv[2]);
    console.log(res);
  })();
} else {
  console.log('请输入商品详情页面Url参数');
  printLine();

  rl.question('', async function (input) {
    printLine();
    console.log('正在爬取，请稍后……');    
    const res = await fetchByUrl(input);
    printLine();
    console.log(res);
    rl.close();
    process.exit();
  });
}
rl.on('SIGINT', () => {
  console.log('操作取消');
  rl.close();
});
